<include file="public@header"/>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInUp js-check-wrap">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>设置权限</h5>
                    <div class="ibox-tools">
                        <a href="{:url('rbac/index')}" class="btn btn-primary btn-xs">{:lang('ADMIN_RBAC_INDEX')}</a>
                        <a href="{:url('rbac/roleAdd')}" class="btn btn-primary btn-xs">{:lang('ADMIN_RBAC_ROLEADD')}</a>
                        <a href="#" class="btn btn-primary btn-xs active">{:lang('ADMIN_RBAC_AUTHORIZE')}</a>
                    </div>
                </div>
                <div class="ibox-content table_full">
                    <form class="js-ajax-form margin-top-20"  action="{:url('rbac/authorizePost')}" method="post">
                    <table class="table table-hover" id="authrule-tree">
                        <tbody>
                            {$category}
                        </tbody>
                    </table>
                    <div class="form-actions">
                <input type="hidden" name="roleId" value="{$roleId}" />
                <button class="btn btn-primary js-ajax-submit" type="submit">{:lang('SAVE')}</button>
                <a class="btn btn-default" href="{:url('admin/rbac/index')}">{:lang('BACK')}</a>
            </div>
        </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        Wind.css('treeTable');
        Wind.use('treeTable', function () {
            $("#authrule-tree").treeTable({
                indent: 20
            });
        });
    });

    function checknode(obj) {
        var chk = $("input[type='checkbox']");
        var count = chk.length;

        var num = chk.index(obj);
        var level_top = level_bottom = chk.eq(num).attr('level');
        for (var i = num; i >= 0; i--) {
            var le = chk.eq(i).attr('level');
            if (le <level_top) {
                chk.eq(i).prop("checked", true);
                var level_top = level_top - 1;
            }
        }
        for (var j = num + 1; j < count; j++) {
            var le = chk.eq(j).attr('level');
            if (chk.eq(num).prop("checked")) {

                if (le > level_bottom){
                    chk.eq(j).prop("checked", true);
                }
                else if (le == level_bottom){
                    break;
                }
            } else {
                if (le >level_bottom){
                    chk.eq(j).prop("checked", false);
                }else if(le == level_bottom){
                    break;
                }
            }
        }
    }
    </script>
</body>
</html>